package user;
import book.BookList;
import operate.*;
import java.util.Scanner;
public class AdminUser extends User {
    /**
     * @param name 把对书的操作功能都写进集合里
     */
    /*
     * 0.返回
     * 1.上架书籍
     * 2.下架书籍
     * 3.展示书籍
     * 4.查找书籍
     *
     * */
    public AdminUser(String name) {
        super(name);
        this.iOperates = new IOperate[]{
            new Exit(),//0
            new Add(),//1
            new Del(),//2
            new Display(),//3
            new Find()//4
        };
    }
    /**
     * @return 打印管理者所看到的菜单
     * 让管理者选择进行什么操作
     * 并把操作返回
     */
    public void menu(User user,BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        //打印管理员所看到的菜单
        while (true) {
            System.out.println("------------图书馆------------");
            printManagerMenu();
            System.out.println("请输入选择：");
            int choice = -1;
            while(true) {
                if (scanner.hasNextInt()) {
                    choice = scanner.nextInt();
                    break;
                } else {
                    System.out.println("非法输入,请重新输入:");
                    scanner.next();
                }
            }
            switch (choice)
            {
                case 1:
                    user.doOperate(user,1,bookList);
                    break;
                case 2:
                    user.doOperate(user,2,bookList);
                    break;
                case 3:
                    user.doOperate(user,3,bookList);
                    break;
                case 4:
                    user.doOperate(user,4,bookList);
                    break;
                case 0:
                    user.doOperate(user,0,bookList);
                    return;
            }
        }
    }
    //打印选项
    private void printManagerMenu() {
        System.out.println("1:上架书籍");
        System.out.println("2:下架书籍");
        System.out.println("3:展示书籍");
        System.out.println("4:查找书籍");
        System.out.println("0:返回主菜单");
    }
}
